package r6.pierwszy.raz;

import java.text.DateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

public class Employee implements Cloneable {

	private String name;
	private final int id = getNextID();
	private Date hireDate;
	private double salary;
	private static int nextID;

	static {
		nextID = 1;
	}

	private int getNextID() {
		return nextID++;
	}

	public Employee(String name, int year, int month, int day, double salary) {
		this.name = name;
		this.hireDate = new GregorianCalendar(year, month - 1, day).getTime();
		this.salary = salary;
	}

	public String getName() {
		return name;
	}

	public int getId() {
		return id;
	}

	public Date getHireDate() {
		return (Date) hireDate.clone();
	}

	public double getSalary() {
		return salary;
	}

	public void increaseSalary(double byPercent) {
		this.salary += this.salary * byPercent / 100;
	}

	@Override
	public String toString() {
		return this.getClass().getSimpleName() + name + ", id="
				+ id + ", " + DateFormat.getDateInstance().format(hireDate) + ", salary=" + salary;
	}

	@Override
	protected Employee clone() throws CloneNotSupportedException {
		Employee cloned = (Employee) super.clone();
		cloned.hireDate = (Date) this.hireDate.clone();
		return cloned;
	}
}
